#define DEBUG
#include <cstdio>
#include <cstdlib>
#define MAXN 100000
#define MAXM 500000

using namespace std;

class Graph {
public:
  int n, m=1, ind[MAXN+1], link[2*MAXN+2], to[2*MAXN+2], degree[MAXN+1], id[2*MAXN+2];
  long long node[MAXN+1], ans[MAXN+1];

  void addSide(int u, int v, int w) {
    m++;
    to[m]=v;
    id[m]=w;
    link[m]=ind[u];
    ind[u]=m;
    degree[u]++;
  }

  void bfs() {
    static int que[MAXN+1];
    int h=0, t=0;
    for (int i=1; i<=n; i++) {
      if (degree[i]==1) {
	que[++t]=i;
      }
    }
    for (; h<t; ) {
      h++;
      for (int i=ind[que[h]]; i; i=link[i]) {
	if (!ans[id[i]]) {
	  ans[id[i]]=node[que[h]];
	  degree[to[i]]--;
	  degree[que[h]]--;
	  node[to[i]]-=ans[id[i]];
	  if (degree[to[i]]==1) {
	    que[++t]=to[i];
	  }
	  break;
	}
      }
    }
  }

  void solve() {
    bfs();

    static int map[MAXN+1], tar[MAXN+1];
    long long sum=0;
    for (int i=1; i<=n; i++) {
      if (degree[i]>1) {
	tar[++tar[0]]=i;
	map[i]=tar[0];
	sum += node[i];
      }
    }
    if (tar[0]) {
      if (tar[0]%2==0) {
	printf("0");
	exit(0);
      }
      sum = sum/2;
      for (int i=3; i<=tar[0]; i+=2) {
	sum -= node[tar[i]];
      }
      node[tar[1]]-=sum;
      node[tar[2]]-=sum;
      degree[tar[1]]--;
      degree[tar[2]]--;
      for (int i=ind[tar[1]]; i; i=link[i]) {
	if (to[i]==tar[2]) {
	  ans[id[i]]=sum;
	  break;
	}
      }

      bfs();
    }
  }
};

int main() {
#ifdef DEBUG
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
#endif

  static Graph g;
  int n, m;
  scanf("%d %d", &n, &m);
  g.n=n;
  if (m>n) {
    printf("0");
    return 0;
  }

  for (int i=1; i<=n; i++) {
    scanf("%lld", &g.node[i]);
  }
  for (int i=1; i<=m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g.addSide(u, v, i);
    g.addSide(v, u, i);
  }

  g.solve();
  for (int i=1; i<=m; i++) {
    printf("%lld\n", g.ans[i]*2);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
